package com.Humanities.base.mybatisplus;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;
import java.time.LocalDateTime;

@Component
public class MyMetaObjectHandler implements MetaObjectHandler {
    //mybatis plus 自动填充功能
    // 插入时自动填充
    @Override
    public void insertFill(MetaObject metaObject) {
        this.strictInsertFill(metaObject, "createDate", LocalDateTime.class, LocalDateTime.now()); // 设置当前时间
        this.strictInsertFill(metaObject, "validtimeStart", LocalDateTime.class, LocalDateTime.now());

    }

    // 更新时自动填充
    @Override
    public void updateFill(MetaObject metaObject) {
        // 如果需要在更新时填充其他字段，可以在这里填充
        this.strictUpdateFill(metaObject, "updateDate", LocalDateTime.class, LocalDateTime.now());
    }
}
